using UnityEngine;

public class banana : MonoBehaviour
{
	public bool Etat;

	public int timeDisapear;

	public AudioSource source;

	public AudioClip PowerAbility;

	private GameManager gManag;

	public GameObject Manager;

	public GameObject Camera;

	public GameObject Parentstick;

	private void Start()
	{
		if (source == null)
		{
			source = GameObject.Find("SoundEffect").GetComponent<AudioSource>();
		}
		timeDisapear = 0;
		Etat = false;
	}

	private void OnEnable()
	{
		timeDisapear = 0;
		Etat = false;
	}

	private void OnDisable()
	{
		if (Etat)
		{
			Debug.Log("reactivation");
			Rigidbody2D[] componentsInChildren = Parentstick.gameObject.GetComponentsInChildren<Rigidbody2D>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (componentsInChildren[i].gameObject.GetComponent<Pied>() != null)
				{
					componentsInChildren[i].gameObject.GetComponent<Pied>().enabled = true;
				}
				if (componentsInChildren[i].gameObject.GetComponent<Equilibre>() != null)
				{
					componentsInChildren[i].gameObject.GetComponent<Equilibre>().enabled = true;
				}
			}
		}
		Etat = false;
		timeDisapear = 0;
	}

	private void FixedUpdate()
	{
		if (!Etat)
		{
			return;
		}
		timeDisapear--;
		if (timeDisapear != 1)
		{
			return;
		}
		Rigidbody2D[] componentsInChildren = Parentstick.gameObject.GetComponentsInChildren<Rigidbody2D>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			if (componentsInChildren[i].gameObject.GetComponent<Pied>() != null)
			{
				componentsInChildren[i].gameObject.GetComponent<Pied>().enabled = true;
			}
			if (componentsInChildren[i].gameObject.GetComponent<Equilibre>() != null)
			{
				componentsInChildren[i].gameObject.GetComponent<Equilibre>().enabled = true;
			}
		}
		base.gameObject.SetActive(false);
	}

	private void OnCollisionEnter2D(Collision2D coll)
	{
		if (Etat || !coll.gameObject.CompareTag("membre") || !(coll.gameObject.GetComponent<Pied>() != null))
		{
			return;
		}
		Parentstick = coll.transform.parent.gameObject;
		Rigidbody2D[] componentsInChildren = Parentstick.gameObject.GetComponentsInChildren<Rigidbody2D>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			if (componentsInChildren[i].gameObject.GetComponent<Pied>() != null)
			{
				componentsInChildren[i].gameObject.GetComponent<Pied>().enabled = false;
				componentsInChildren[i].AddTorque(Random.Range(-60, 60), ForceMode2D.Impulse);
				componentsInChildren[i].AddForce(new Vector2(0f, 8f), ForceMode2D.Impulse);
			}
			if (componentsInChildren[i].gameObject.GetComponent<Equilibre>() != null)
			{
				componentsInChildren[i].gameObject.GetComponent<Equilibre>().enabled = false;
				componentsInChildren[i].AddTorque(Random.Range(-60, 60), ForceMode2D.Impulse);
			}
		}
		Etat = true;
		timeDisapear = 100;
	}
}
